<template>
	<view class="flex-container main">
		<!-- 搜索 -->
		<app-search @toSearch="toSearch" :shows="false" @clickadd="add"></app-search>

		<!-- banner -->
		<view class="banner">
			<view class="banner-bg">
				<!-- <u-swiper height="268" :list="banner" imgMode="fill"></u-swiper> -->
				<view class="ad">
					<ad-custom unit-id="adunit-2dec9090f17cec3e" @load="adLoad" @error="adError"
						@close="adClose"></ad-custom>
				</view>
			</view>
		</view>
		<!-- <view class="menu" style="margin-bottom: 5rpx;">
			<button class="acquire_score" >魔法相机</button>
		</view> -->
		<!-- 菜单 -->
		<view class="menu">
			<view class="menu-item" @click="toMfxj">
				<image :src="$imgUrl('/symf.png')" mode="scaleToFill" />
				<view>魔法相机</view>
			</view>
			<view class="menu-item" @click="toDrawing">
				<image :src="$imgUrl('/menu1.png')" mode="scaleToFill" />
				<view>AI绘画</view>
			</view>
			<view class="menu-item" @click="toCartoon">
				<image :src="$imgUrl('/menu2.png')" mode="scaleToFill" />
				<view>人物动漫画</view>
			</view>
			<view class="menu-item" @click="toRepair">
				<image :src="$imgUrl('/menu3.png')" mode="scaleToFill" />
				<view>图像修复</view>
			</view>
			<view class="menu-item" @click="toWsfd">
				<image :src="$imgUrl('/menu4.png')" mode="scaleToFill" />
				<view>图片无损放大</view>
			</view>
		</view>

		<view class="list" v-if="list.length">
			<view class="list-item" v-for="(i, index) in list" :key="index" @tap="onclickList(i)">
				<image class="list-item-img" v-if="i.url" :src="i.url" mode="scaleToFill" />
				<image class="list-item-img" v-else :src="$imgUrl('/1725513206439.jpg')" mode="scaleToFill" />
				<view class="list-item-name">{{ i.mc }}</view>
				<view class="list-item-date" v-if="i.cjsj">{{ i.cjsj.substring(0, 10) }}</view>
			</view>
		</view>
		<view class="nocontent" v-else>
			<u-empty mode="list" icon="https://wx93.cn/upload/image/list.png" text="暂无相册"></u-empty>
		</view>
	</view>

</template>

<script>
	import appSearch from '@/components/app-search';
	import {
		getLocationInf,
		getLocation
	} from '@/nxTemp/utils/locationUtils.js';
	export default {
		components: {
			appSearch
		},
		data() {
			return {
				search: '',
				//banner: [require('@/static/images/banrer.jpg')],
				list: []
			};
		},
		onLoad() {
			this.getLocationAddress();
			// this.getPhotoList();
		},
		methods: {
			toMfxj() {
				uni.switchTab({
					url: '/pages/ar/index'
				});
			},
			adLoad() {
				console.log('原生模板广告加载成功');
			},
			adError(err) {
				console.error('原生模板广告加载失败', err);
			},
			adClose() {
				console.log('原生模板广告关闭');
			},
			/**
			 * 获取轮播图
			 */
			async getBanner() {
				// 	let res = await this.$http.get('/app/lbt/list');
				// 		this.banner = res.list;
			},

			onShow() {
				if (uni.getStorageSync('token') !== null && uni.getStorageSync('token') !== undefined && uni
					.getStorageSync('token') !== '') {
					this.getPhotoList();
				}
			},
			toAi() {
				uni.navigateTo({
					url: '/pages/subpackage/mp_authorization'
				});
			},
			//授权获取地址
			getLocationAddress() {
				getLocation()
					.then((result) => {
						console.log(result);
					})
					.catch((error) => {
						console.log(error);
					});
			},
			toSearch(message) {
				this.search = message;
				this.getPhotoList();
			},
			//  获取相册信息
			async getPhotoList() {
				let res = await this.$http.get('/app/xc/getSyXc', {
					mc: this.search
				});
				if (res.code == 0) {
					this.list = res.list;
				}
			},
			// 跳转详情页面
			onclickList(e) {
				console.log(e)
				uni.navigateTo({
					url: '/pages/photo/list?id=' + e.id + '&lx=' + e.lx + '&mc=' + e.mc
				});
			},
			toDrawing() {
				uni.navigateTo({
					url: '/pages/subpackage/ai/drawing'
				});
			},
			toCartoon() {
				uni.navigateTo({
					url: '/pages/subpackage/ai/cartoon'
				});
			},
			toRepair() {
				uni.navigateTo({
					url: '/pages/subpackage/ai/repair'
				});
			},
			toWsfd() {
				uni.navigateTo({
					url: '/pages/subpackage/ai/wsfd'
				});
			},
			toBusinessCard() {
				uni.navigateTo({
					url: '/pages/subpackage/ai/businessCard'
				});
			}
		}
	};
</script>
<style>
	page {
		background-color: #000;
	}
</style>
<style lang="scss" scoped>
	.list {
		display: flex;
		width: 700rpx;
		margin: 0rpx 25rpx;
		flex-wrap: wrap;
		box-sizing: border-box;
		justify-content: space-between;
		// height: 720rpx;
		overflow-y: auto;

		&-item {
			margin: 16rpx 0;
			// background-image: url('../../static/image/photo_bg.png');
			background-image: url($imgUrl + '/photo_bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			width: 340rpx;
			height: 340rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			overflow: hidden;

			&-img {
				width: 300rpx;
				height: 270rpx;
			}

			&-name {
				font-size: 24rpx;
				position: absolute;
				bottom: 80rpx;
				left: 30rpx;
				color: #fff;
			}

			&-date {
				font-size: 24rpx;
				position: absolute;
				bottom: 40rpx;
				left: 30rpx;
				color: #fff;
			}
		}
	}

	.title {
		width: 180rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		view {
			line-height: 34rpx;
			font-size: 34rpx;
			color: #fff;
			font-weight: bold;
		}

		image {
			margin-top: 4rpx;
			width: 50rpx;
			height: 10rpx;
		}
	}

	.menu {
		height: 170rpx;
		padding: 25rpx 0;
		background-image: url($imgUrl + '/menu_bg.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 700rpx;
		margin: 40rpx 25rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;

		&-item {
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				margin-top: 10rpx;
				width: 60rpx;
				height: 60rpx;
			}

			view {
				margin-top: 10rpx;
				color: #fff;
				font-size: 22rpx;
			}
		}
	}

	.acquire_score {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 300rpx;
		height: 60rpx;
		color: #333;
		font-family: PingFangSC;
		color: #ffffff;
		font-weight: 500;
		font-size: 26rpx;
		padding: 0;
		border-radius: 50px;
		background: linear-gradient(90deg, #13b1a2 0%, #276329 100%);
		border: none;
		margin-top: 30rpx;
	}

	.banner {
		margin-top: calc(var(--status-bar-height) + 170rpx);
		display: flex;
		justify-content: center;
		align-items: center;

		&-bg {
			// background-image: url('../../static/image/banner_bg.png');
			background: url($imgUrl + '/banner_bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 6rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
			width: 700rpx;
			height: 384rpx;

			@include center();

			.ad {
				width: 96% !important;
				height: 100% !important;
			}
		}
	}
</style>